package com.nageoffer.jobtrain.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nageoffer.jobtrain.admin.dto.req.OjQuestionAddReqDTO;
import com.nageoffer.jobtrain.admin.dto.req.OjQuestionEditReqDTO;
import com.nageoffer.jobtrain.admin.dto.req.OjQuestionPageReqDTO;
import com.nageoffer.jobtrain.admin.dto.resp.OjQuestionDetailRespDTO;
import com.nageoffer.jobtrain.admin.dto.resp.OjQuestionPageRespDTO;
import com.nageoffer.jobtrain.admin.service.OjQuestionService;
import com.nageoffer.jobtrain.common.web.result.Result;
import com.nageoffer.jobtrain.common.web.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * author：唐晨
 * Oj题目模块接口控制层
 */
@RestController
@RequiredArgsConstructor
public class OjQuestionController {
    private final OjQuestionService ojQuestionService;

    /**
     * 根据题目难度/标题分页查询Oj题目
     */
    @PostMapping("/api/job-train/admin/oj/page")
    public Result<IPage<OjQuestionPageRespDTO>> ojQuestionPageList(@RequestBody OjQuestionPageReqDTO requestParam) {
        return Results.success(ojQuestionService.ojQuestionPageList(requestParam));
    }

    /**
     * 新增Oj题目管理
     */
    @PostMapping("/api/job-train/admin/oj/add")
    public Result<Void> addOjQuestion(@RequestBody OjQuestionAddReqDTO requestParam) {
        ojQuestionService.addOjQuestion(requestParam);
        return Results.success();
    }

    /**
     * 根据Oj题目ID获取题目详情
     */
    @GetMapping("/api/job-train/admin/oj/get-detail")
    public Result<OjQuestionDetailRespDTO> getOjQuestionDetailById(@RequestParam("id") Long id) {
        return Results.success(ojQuestionService.getOjQuestionDetailById(id));
    }

    /**
     * 编辑Oj题目详情
     */
    @PostMapping("/api/job-train/admin/oj/edit")
    public Result<Void> updateOjQuestionDetail(@RequestBody OjQuestionEditReqDTO requestParam) {
        ojQuestionService.updateOjQuestionDetail(requestParam);
        return Results.success();
    }

    /**
     * 删除Oj题目详情
     */
    @DeleteMapping("/api/job-train/admin/oj/delete")
    public Result<Void> deleteOjQuestionDetail(@RequestParam("id") Long id) {
        ojQuestionService.deleteOjQuestionDetail(id);
        return Results.success();
    }
}
